//HT1622驱动的段码屏

#include "../main.h"
#include "HT162X_Pin.h"


#define Lcd_GPIO_PIN_SEL  ((1ULL<<IO_Lcd_CS) | (1ULL<<IO_Lcd_WR) | (1ULL<<IO_Lcd_Data) | (1ULL<<IO_Lcd_ON_OFF))
#define Lcd_GPIO_PIN_OD  ((1ULL<<IO_Lcd_CS) | (1ULL<<IO_Lcd_WR))

#define Lcd_CS_H gpio_set_level(IO_Lcd_CS,1)
#define Lcd_CS_L gpio_set_level(IO_Lcd_CS,0)
// #define Lcd_RD_H gpio_set_level(IO_Lcd_RD,1)
// #define Lcd_RD_L gpio_set_level(IO_Lcd_RD,0)
#define Lcd_WR_H gpio_set_level(IO_Lcd_WR,1)
#define Lcd_WR_L gpio_set_level(IO_Lcd_WR,0)
#define IO_Lcd_Data_H gpio_set_level(IO_Lcd_Data,1)
#define IO_Lcd_Data_L gpio_set_level(IO_Lcd_Data,0)

// #define IO_Lcd_IRQ_H gpio_set_level(IO_Lcd_IRQ,1)


void HT162X_Pin_Config(void)
{
    gpio_config_t io_conf;
    gpio_config_t io_conf2;

    //disable interrupt
    io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
    //set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = Lcd_GPIO_PIN_SEL;
    //disable pull-down mode
    io_conf.pull_down_en = 0;
    //disable pull-up mode
    io_conf.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf);  


    //disable interrupt
    io_conf2.intr_type = GPIO_PIN_INTR_DISABLE;
    //set as output mode
    io_conf2.mode = GPIO_MODE_OUTPUT_OD;
    //bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf2.pin_bit_mask = Lcd_GPIO_PIN_OD;
    //disable pull-down mode
    io_conf2.pull_down_en = 0;
    //disable pull-up mode
    io_conf2.pull_up_en = 0;
    //configure GPIO with the given settings
    gpio_config(&io_conf2);  
    
    Lcd_CS_H;
    // Lcd_RD_H;
    Lcd_WR_H;
    IO_Lcd_Data_H;
    // IO_Lcd_IRQ_H;
    IO_Lcd_ON_OFF_L;
}

void HT162X_CS_Handled(uint8_t val)
{
    if(val == 0) Lcd_CS_L;
    else Lcd_CS_H;
}
void HT162X_RD_Handled(uint8_t val)
{
    // if(val == 0) Lcd_RD_L;
    // else Lcd_RD_H;
}
void HT162X_WR_Handled(uint8_t val)
{
    if(val == 0) Lcd_WR_L;
    else Lcd_WR_H;
}
void HT162X_Data_Handled(uint8_t val)
{
    if(val == 0) IO_Lcd_Data_L;
    else IO_Lcd_Data_H;
}
